/*
 * @Author: shijianxin
 * @Date: 2022-04-22 15:27:46
 * @Description: 电影api请求
 */
import axios from "axios";
import {
  IResponseData,
  IResponseError,
  IResponsePageData,
  ISearchCondition,
} from "./CommonType";

export interface IMovie {
  _id?: string;
  name: string;
  types: string[];
  areas: string[];
  timeLong: number;
  isHot: boolean;
  isComing: boolean;
  isClassic: boolean;
  description?: string;
  poster?: string;
}

export class MovieService {
  public static async add(
    movie: IMovie
  ): Promise<IResponseData<IMovie> | IResponseError> {
    const { data } = await axios.post("/api/movie", movie);
    return data;
  }

  public static async edit(
    id: string,
    movie: Partial<IMovie>
  ): Promise<IResponseData<true> | IResponseError> {
    const { data } = await axios.put("/api/movie/" + id, movie);
    return data;
  }

  public static async delete(
    id: string
  ): Promise<IResponseData<true> | IResponseError> {
    const { data } = await axios.delete("/api/movie/" + id);
    return data;
  }

  public static async getMovieById(
    id: string
  ): Promise<IResponseData<IMovie | null>> {
    const { data } = await axios.get("/api/movie/" + id);
    return data;
  }

  public static async getMovies(
    condition: ISearchCondition
  ): Promise<IResponsePageData<IMovie>> {
    const { data } = await axios.get("/api/movie/", {
      params: condition,
    });
    return data;
  }
}
